package com.sy.controller;


import com.sy.demo.Cat;
import com.sy.service.WelcomeService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;


@Controller
public class WelcomeController implements ApplicationContextAware {

	private String myName;

	private Cat cat;

	// 加上 Autowired 就是自动装配
	@Autowired
	public void setCat(Cat cat) {
		this.cat = cat;
	}

	public void setMyName(String myName) {
		this.myName = myName;
	}

	private ApplicationContext myContext;

	public WelcomeController() {
		System.out.println("WelcomeController创建了。。。。。。。");
	}


	@Autowired
	private WelcomeService welcomeService;

	public void testRequest() {
		welcomeService.sayHello("Hello Controller");
		System.out.println("WelcomeController---" + myName);
		System.out.println("WelcomeController---" + myContext);
	}



	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.myContext = applicationContext;
	}
}
